
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytools;

import com.opensymphony.xwork2.ActionSupport;
import java.sql.SQLException;
import java.util.List;

/**

 *

 * @author wl

 */
public class questionoperation extends ActionSupport {

    private int id;
    private question question;
    private String subject;
    private String chapter;
    private String chapterinfo;
    private String type;
    private String name;
    private String level;
    private String answer;
    private questionDAO qd;
    private question addquestion;
    private List<question> questionlist;

    public questionoperation() {
    }

    public String questionlist() throws SQLException, Exception {
        qd = new questionDAO();
        setQuestionlist(qd.questionlist());
        return SUCCESS;
    }

    public String questionadd() throws Exception {
        setQd(new questionDAO());
        int i = getQd().addquestion(getAddquestion());
        if (i == 1) {
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    public String questiondelete() throws Exception {
        setQd(new questionDAO());
        int i = getQd().deletequestion(getId());
        if (i == 1) {
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    public String questionedit() throws Exception {
        question question = new question();
        question.setAnswer(getAnswer());
        question.setChapter(getChapter());
        question.setChapterinfo(getChapterinfo());
        question.setId(getId());
        question.setName(getName());
        question.setLevel(getLevel());
        question.setType(getType());
        question.setSubject(getSubject());
        questionDAO qd = new questionDAO();
        int i = qd.editquestion(question);
        if (i > 0) {
            return SUCCESS;
        } else {
            return INPUT;
        }
    }

    public String questionview() throws Exception {
        questionDAO qd = new questionDAO();
        setQuestion(qd.getquestion(getId()));
        return SUCCESS;
    }

    public String execute() throws Exception {
        return SUCCESS;


    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the question
     */
    public question getQuestion() {
        return question;
    }

    /**
     * @param question the question to set
     */
    public void setQuestion(question question) {
        this.question = question;
    }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * @return the chapter
     */
    public String getChapter() {
        return chapter;
    }

    /**
     * @param chapter the chapter to set
     */
    public void setChapter(String chapter) {
        this.chapter = chapter;
    }

    /**
     * @return the chapterinfo
     */
    public String getChapterinfo() {
        return chapterinfo;
    }

    /**
     * @param chapterinfo the chapterinfo to set
     */
    public void setChapterinfo(String chapterinfo) {
        this.chapterinfo = chapterinfo;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the level
     */
    public String getLevel() {
        return level;
    }

    /**
     * @param level the level to set
     */
    public void setLevel(String level) {
        this.level = level;
    }

    /**
     * @return the answer
     */
    public String getAnswer() {
        return answer;
    }

    /**
     * @param answer the answer to set
     */
    public void setAnswer(String answer) {
        this.answer = answer;
    }

    /**
     * @return the qd
     */
    public questionDAO getQd() {
        return qd;
    }

    /**
     * @param qd the qd to set
     */
    public void setQd(questionDAO qd) {
        this.qd = qd;
    }

    /**
     * @return the addquestion
     */
    public question getAddquestion() {
        return addquestion;
    }

    /**
     * @param addquestion the addquestion to set
     */
    public void setAddquestion(question addquestion) {
        this.addquestion = addquestion;
    }

    /**
     * @return the questionlist
     */
    public List<question> getQuestionlist() {
        return questionlist;
    }

    /**
     * @param questionlist the questionlist to set
     */
    public void setQuestionlist(List<question> questionlist) {
        this.questionlist = questionlist;
    }
}
